<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue v-bind:style</title>
    <script src="./js/vue.min.js"></script>
    <style>
        div {
            margin: 30px 0;
        }
        
        .red {
            color: #ff0000;
        }
        
        .green {
            color: #079407;
        }
        
        .fz26 {
            font-size: 26px;
        }
        
        .show {
            display: block;
        }
        
        .hide {
            display: none;
        }
    </style>
</head>

<body>

    <div id="vm">

        <div>
            设置a的值 <input type="text" v-model="a" />
        </div>
        <div v-bind:class="{red:a==1}">
            v-bind:class 单条件表达式 v-bind:class="{red:a==1}"
        </div>
        <div v-bind:class="{green:a==2}">
            v-bind:class 单条件表达式 v-bind:class="{red:a==2}"
        </div>
        <div v-bind:class="{red:a==1,green:a==2}">
            v-bind:class 多条件表达式 v-bind:class="{red:a==1,green:a==2}"
        </div>

        <div v-bind:class="classObject1">
            v-bind:class 初始化对象值 v-bind:class="classObject1"
        </div>

        <div v-bind:class="classObject2">
            v-bind:class 计算对象值 v-bind:class="classObject2"
        </div>

        <div :class="{hide:a==0,show:a==1}">
            :class 控制显示隐藏 v-bind:class="{hide:a==0,show:a==1}"
        </div>

        <div>
            <button v-on:click="setShow()">显示</button>
            <button v-on:click="setHide()">隐藏</button>
        </div>

    </div>

    <script>
        var vm01 = new Vue({
            el: '#vm',
            data: {
                a: 0,
                classObject1: {
                    'red': true,
                    'fz26': true
                }
            },
            computed: {
                //计算
                classObject2: function() {
                    return {
                        'red': this.a == 1,
                        'green': this.a == 2
                    }
                }
            },
            methods: {
                setShow() {
                    this.a = 1;
                },
                setHide() {
                    this.a = 0;
                }
            }
        })
    </script>

</body>

</html>